
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>
<div id="page-wrapper">


    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Đánh giá thái độ</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Danh sách
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="form-group">
                        <label>Đợt đánh giá</label>
                        <input type="text" name="name" class="form-control" style="width: 50%;" readonly="readonly" value="<?php echo $evaluationInfo['name']; ?>" />
                    </div>

                    <div class="col-lg-12">
                        Team leader 
                        <select class="form-control display-inline" name="filter-tl" style="width: 200px;">
                            <option value="all">Tất cả</option>
                            <?php foreach ($teamleaders as $eachTL) { ?>
                                <option value="<?php echo $eachTL['code']; ?>" <?php echo ($filterTL == $eachTL['code']) ? 'selected="selected"' : ''; ?>><?php echo $eachTL['name']; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Nhóm
                        <select class="form-control display-inline" name="filter-title" style="width: 100px;">
                            <option value="all">Tất cả</option>
                            <?php
                            foreach ($titles as $key => $value) {
                                ?>
                                <option value="<?php echo $value; ?>" <?php echo ($filterTitle == $value) ? 'selected="selected"' : ''; ?>><?php echo $key; ?></option>
                            <?php } ?>
                        </select>
                        <br><br>
                    </div>


                    <?php
                    if ($rows == false) {
                        ?>
                        Hiện tại không có kết quả nào!
                        <br>
                    <?php } else { ?>

                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover" id="main-table">
                                <thead>
                                    <tr>
                                        <th width="90px">Area</th>
                                        <th width="110px">Location</th>
                                        <th width="110px">Mã NV</th>
                                        <th>Title</th>
                                        <th>Họ và tên</th>

                                        <th>&nbsp;</th>
                                        <th>Số điểm</th>
                                        <th>Xếp loại</th>
                                        <th>Ngày đánh giá</th>
                                        
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($rows as $row) { ?>
                                        <tr>
                                            <td><?php echo $regionDic[$row['rsm_code']]; ?></td>
                                            <td><?php echo $row['location']; ?></td>
                                            <td style="vertical-align: middle;"><?php echo $row['code']; ?></td>
                                            <td style="vertical-align: middle;"><?php echo $row['title']; ?></td>
                                            <td style="vertical-align: middle;"><?php echo $row['name']; ?></td>

                                            <td style="vertical-align: middle;">
                                                <?php
                                                if (strtotime($row['starting_day']) < strtotime(date('Y-5-1'))) { // làm việc trước ngày 1/5 mới xét
                                                    if ($row['attResult']['status'] == 'confirmed') {
                                                        echo ucfirst($row['attResult']['status']);
                                                    } else {
                                                        if (!$row['attResult']['rated_day']) {
                                                            ?>
                                                            <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/attitude_user_details/add/' . $row['id']); ?>">Đánh giá</a>
                                                        <?php } else { ?>
                                                            <?php if ($row['attResult']['status'] == 'rejected') { ?>
                                                                Rejected<br/>
                                                            <?php } else if ($row['attResult']['status'] == 'review') { ?>
                                                                Waiting review<br/>
                                                            <?php } ?>
                                                            <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/attitude_user_details/edit/' . $row['id']); ?>">Đánh giá lại</a>

                                                            <?php
                                                        }
                                                    }
                                                }
                                                ?>
                                            </td>
                                            <td style="vertical-align: middle;"><?php echo $row['attResult']['score']; ?></td>
                                            <td style="vertical-align: middle;"><?php echo color_attitude($row['attResult']['score'], $settings['att_high_score'], $settings['att_medium_score'], $row['attResult']['rating']); ?></td>
                                            <td style="vertical-align: middle;"><?php echo $row['attResult']['rated_day']; ?></td>
                                            
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>

                        </div>
                    <?php } ?>
                    <br>
<!--                    <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/attitude_detail_results/add'); ?>"> <img src="<?php echo base_url(); ?>images/plus.png" title="Thêm bảng đánh giá mới"> Thêm bảng đánh giá mới</a>
                    <br>-->
                </div>
                <!-- /.panel-body -->
            </div>
        </div>
    </div>


</div>
<script>
    function search()
    {
        var tl_code = "";
        var title = "";

        $("select[name=filter-tl] option:selected").each(function() {
            tl_code += $(this).val();
        });
        $("select[name=filter-title] option:selected").each(function() {
            title = $(this).val();
        });
        window.location = '<?php echo site_url(get_folder($loggedUser['title']) . '/attitude_detail_results/index') ?>' + '/' + tl_code + '/' + title;
    }

    $(document).ready(function() {
        var table = $('#main-table').dataTable({
            //"iDisplayLength": 50,
//            "scrollX": true,
//            "sScrollX": "120%",
//            "order": [[11, "desc"]],
//            "columnDefs": [
//                {
//                    "targets": [0],
//                    "visible": false,
//                    "searchable": false,
//                    "orderData": [0, 1]
//                },
//                {
//                    "targets": [1],
//                    "visible": false,
//                    "searchable": false,
//                    "orderData": [0, 1]
//                },
//                {
//                    "targets": [2],
//                    "visible": false,
//                    "searchable": false,
//                    "orderData": [0, 1]
//                },
//            ]
        });


        $('select[name=filter-tl]').change(function() {
            search();
        });
        $('select[name=filter-title]').change(function() {
            search();
        });
    });
</script>

<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>
